package com.by.rpc.util;

/**
 * 注册中心键名工具类
 * 用于构建和解析注册中心的键名
 */
public class KeyUtils {

    public static final String RPC_ENDPOINT_SERVICE = "api:endpoint";
    public static final String RPC_SPLIT = ":";

    public static final String SERVICE_PREFIX = "rpc:service";
    public static final String SERVICE_INTERFACE_PREFIX = "service:interface";
    public static final String SERVICE_STATUS_PREFIX = "service:status";

    /**
     * 构建服务实例键名
     *
     * @param serviceName 服务名称
     * @return 键名
     */
    public static String buildReferenceServiceKey(String serviceName, String version, String group) {
        return SERVICE_PREFIX + RPC_SPLIT + serviceName + RPC_SPLIT + version + RPC_SPLIT + group;
    }

    /**
     * 构建API端点键名
     *
     * @param serviceName 服务名称
     * @param version     版本
     * @param group       分组
     * @return 键名
     */
    public static String buildRpcEndpointKey(String serviceName, String version, String group) {
        return RPC_ENDPOINT_SERVICE + RPC_SPLIT + serviceName + RPC_SPLIT + version + RPC_SPLIT + group;
    }

    public static String buildServiceKey(String serviceName, String version, String group) {
        return SERVICE_PREFIX + RPC_SPLIT + serviceName + RPC_SPLIT + version + RPC_SPLIT + group;
    }

    public static String buildRpcEndpointMethodKey(String serviceName, String version, String group, String path, String httpMethod) {
        return RPC_ENDPOINT_SERVICE + RPC_SPLIT + serviceName + RPC_SPLIT + version + RPC_SPLIT + group + RPC_SPLIT + path + RPC_SPLIT + httpMethod;
    }

    public static String buildInnerCacheServiceKey(String serviceName, String version, String group) {
        return  serviceName + RPC_SPLIT + version + RPC_SPLIT + group;
    }
}